package ClassTest;

import org.junit.Test;

import static org.junit.Assert.*;

/**
 * Created by 春旺 on 2017/9/22.
 */
public class BagTest {
    Bag<Student> bag = new Bag<>();
    Student s1 = new Student();
    @Test
    public void getCurrentSize() throws Exception {

        Student s1 = new Student();

        assertEquals(0,bag.getCurrentSize());
        bag.add(s1);
        assertEquals(1, bag.getCurrentSize());

    }

    @Test
    public void isEmpty() throws Exception {
       assertEquals(true,bag.isEmpty());
        Student s1 = new Student();
        bag.add(s1);
        assertEquals(false,bag.isEmpty());

    }

    @Test
    public void add() throws Exception {
        assertEquals(true,bag.add(null));
        bag.add(s1);
        assertEquals(true,bag.add(s1));
    }

    @Test
    public void remove() throws Exception {
        bag.add(s1);
        bag.remove();
        assertEquals(0,bag.getCurrentSize());

    }

    @Test
    public void remove1() throws Exception {
        Student s2 = new Student();
        Student s3 = new Student();
        Student s4 = new Student();
        bag.add(s1);   bag.add(s2);
        bag.add(s3);   bag.add(s4);
        bag.add(s1);   bag.add(s2);
        bag.add(s3);   bag.add(s4);
        assertEquals(8,bag.getCurrentSize());
        bag.remove(s2);
        assertEquals(6,bag.getCurrentSize());
    }

    @Test
    public void clear() throws Exception {
        for (int i = 0;i<100;i++){
            bag.add(s1);
        }
        assertEquals(100,bag.getCurrentSize());
       bag.clear();
       assertEquals(0,bag.getCurrentSize());

    }

    @Test
    public void getFrequencyOf() throws Exception {
        Student s2 = new Student();
        Student s3 = new Student();
        for (int i = 0;i < 50;i++){
           bag.add(s2);
           bag.add(s1);
        }
        assertEquals(50,bag.getFrequencyOf(s1));
        assertEquals(0,bag.getFrequencyOf(s3));
    }

    @Test
    public void contains() throws Exception {
        Student s2 = new Student();
        Student s3 = new Student();
        for (int i = 0;i < 50;i++){
            bag.add(s2);
            bag.add(s1);
        }
        assertEquals(true,bag.contains(s2));
        assertEquals(false,bag.contains(s3));
    }

}